/*
 * @Description: 
 * @Author: Liu Kunpeng
 * @Date: 2021-07-05 20:41:06
 */
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const baseRoutes = [
  {
    path: '/',
    redirect: '/login',
    // component: () => import('@/views/Login'),
    // hidden: true
  },

  {
    path: '/login',
    component: () => import('@/views/Login'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path:'/home',
    component: Layout,
    children: [{
      path: 'index',
      name: 'Home',
      component: () => import('@/views/data/Welcome'),
      meta: { title: '首页', icon: 'el-icon-s-home', roles: ['admin', 'manager', 'editor']}
    }]
  },
  {
    path: '/profile',
    component: Layout,
    children: [{
      path: 'profile',
      name: 'profile',
      hidden: true,
      component: () => import('@/views/Profile'),
      meta: { title: '个人中心', roles: ['admin', 'manager', 'editor']}
    }]
  },
  {
    path: '/message',
    component: Layout,
    children: [{
      path: 'message',
      name: 'message',
      hidden: true,
      component: () => import('@/views/MessageBox'),
      meta: { title: '消息中心', roles: ['admin', 'manager', 'editor']}
    }]
  },

  {
    path: '/preview',
    component: Layout,
    children: [{
      path: 'preview',
      name: 'preview',
      hidden: true,
      component: () => import('@/views/PreviewPDF'),
      meta: { title: '报告预览', roles: ['admin', 'manager', 'editor']}
    }]
  },
]

//不需要动态访问的路由  (未用到)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/Login'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    
    path:'/home',
    component: Layout,
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/data/Welcome'),
      meta: { title: '首页', icon: 'el-icon-s-home', roles: ['admin', 'manager', 'editor']}
    }]
  },
  {
    path: '/profile',
    component: Layout,
    children: [{
      path: 'profile',
      name: 'profile',
      hidden: true,
      component: () => import('@/views/Profile'),
      meta: { title: '个人中心', roles: ['admin', 'manager', 'editor']}
    }]
  },
  {
    path: '/message',
    component: Layout,
    children: [{
      path: 'message',
      name: 'message',
      hidden: true,
      component: () => import('@/views/MessageBox'),
      meta: { title: '消息中心', roles: ['admin', 'manager', 'editor']}
    }]
  },

  {
    path: '/preview',
    component: Layout,
    children: [{
      path: 'preview',
      name: 'preview',
      hidden: true,
      component: () => import('@/views/PreviewPDF'),
      meta: { title: '报告预览', roles: ['admin', 'manager', 'editor']}
    }]
  },

  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/AdminList',
    name: 'admin',
    meta: { title: '账户管理', icon: 'el-icon-location' },
    children: [
      {
        path: 'AdminList',
        name: 'AdminList',
        component: () => import('@/views/admin/AdminList'),
        meta: { title: '员工管理', icon: 'el-icon-user-solid',roles: ['admin', 'manager'] }
      },
      {
        path: 'UserList',
        name: 'UserList',
        component: () => import('@/views/admin/UserList'),
        meta: { title: '用户管理', icon: 'el-icon-user', roles: ['admin', 'manager', 'editor']}
      }
    ]
  },
  
  // {
  //   path: '/data',
  //   component: Layout,
  //   meta: { title: '数据管理', icon: 'el-icon-s-data', roles: ['admin', 'manager', 'editor']},
  //   children: [
  //     {
  //       path: 'DataManage01',
  //       name: 'DataManage01',
  //       component: () => import('@/views/data/DataManage01'),
  //       meta: { title: '步态分析', icon: 'butai' }
  //     },
  //     {
  //       path: 'DataManage02',
  //       name: 'DataManage02',
  //       component: () => import('@/views/data/DataManage02'),
  //       meta: { title: '三维扫描', icon: '3dscan' }
  //     },
  //   ]
  // },
  // {
  //   path: '/device',
  //   component: Layout,
  //   meta: { title: '设备管理', icon: 'el-icon-setting', roles: ['admin', 'manager', 'editor'] },
  //   children: [
  //     {
  //       path: 'Device01',
  //       name: 'Device01',
  //       component: () => import('@/views/device/Device01'),
  //       meta: { title: '步态分析', icon: 'butai' }
  //     },
  //     {
  //       path: 'Device02',
  //       name: 'Device02',
  //       component: () => import('@/views/device/Device02'),
  //       meta: { title: '三维扫描', icon: '3dscan' }
  //     },
  //   ]
  // },
  {
    path: '/roles',
    component: Layout,
    meta: { title: '权限管理', icon: 'roles' },
    children: [
      {
        path: 'RoleManage',
        name: 'RoleManage',
        component: () => import('@/views/roles/RoleManage'),
        meta: { title: '角色管理', icon: 'jiaose', roles: ['admin', 'manager']}
      },
      {
        path: 'DataMonitor',
        name: 'DataMonitor',
        component: () => import('@/views/roles/DataMonitor'),
        meta: { title: '数据监控', icon: 'dashboard' }
      },
    ]
  }
  
]
//需要动态判断权限的页面
export const asyncRoutes = [
  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/AdminList',
    name: 'admin',
    meta: { title: '账户管理', icon: 'el-icon-location' },
    children: [
      {
        path: 'AdminList',
        name: 'AdminList',
        component: () => import('@/views/admin/AdminList'),
        meta: { title: '员工管理', icon: 'el-icon-user-solid',roles: ['admin', 'manager'] }
      },
      {
        path: 'UserList',
        name: 'UserList',
        component: () => import('@/views/admin/UserList'),
        meta: { title: '用户管理', icon: 'el-icon-user', roles: ['admin', 'manager', 'editor']}
      }
    ]
  },

  {
    path: '/butai',
    component: Layout,
    meta: { title: '四维步态', icon: 'butai', roles: ['admin', 'manager', 'editor']},
    children: [
      {
        path: 'Device01',
        name: 'Device01',
        component: () => import('@/views/device/Device01'),
        meta: { title: '设备管理', icon: 'device' }
      },
      {
        path: 'DataManage01',
        name: 'DataManage01',
        component: () => import('@/views/data/DataManage01'),
        meta: { title: '数据中心', icon: 'datacenter' }
      },
    ]
  },
  {
    path: '/3dscan',
    component: Layout,
    meta: { title: '三维扫描', icon: '3dscan', roles: ['admin', 'manager', 'editor']},
    children: [
      {
        path: 'Device02',
        name: 'Device02',
        component: () => import('@/views/device/Device02'),
        meta: { title: '设备管理', icon: 'device' }
      },
      {
        path: 'DataManage02',
        name: 'DataManage02',
        component: () => import('@/views/data/DataManage02'),
        meta: { title: '数据中心', icon: 'datacenter' }
      },
    ]
  },
  {
    path: '/data',
    component: Layout,
    meta: { title: '数据管理', icon: 'el-icon-s-data', roles: ['admin', 'manager', 'editor']},
    children: [
      {
        path: 'DataManage01',
        name: 'DataManage01',
        component: () => import('@/views/data/DataManage01'),
        meta: { title: '步态分析', icon: 'butai' }
      },
      {
        path: 'DataManage02',
        name: 'DataManage02',
        component: () => import('@/views/data/DataManage02'),
        meta: { title: '三维扫描', icon: '3dscan' }
      },
    ]
  },
  {
    path: '/device',
    component: Layout,
    meta: { title: '设备管理', icon: 'el-icon-setting', roles: ['admin', 'manager', 'editor'] },
    children: [
      {
        path: 'Device01',
        name: 'Device01',
        component: () => import('@/views/device/Device01'),
        meta: { title: '步态分析', icon: 'butai' }
      },
      {
        path: 'Device02',
        name: 'Device02',
        component: () => import('@/views/device/Device02'),
        meta: { title: '三维扫描', icon: '3dscan' }
      },
    ]
  },
  {
    path: '/roles',
    component: Layout,
    meta: { title: '权限管理', icon: 'roles' },
    children: [
      {
        path: 'RoleManage',
        name: 'RoleManage',
        component: () => import('@/views/roles/RoleManage'),
        meta: { title: '角色管理', icon: 'jiaose', roles: ['admin', 'manager']}
      },
      {
        path: 'DataMonitor',
        name: 'DataMonitor',
        component: () => import('@/views/roles/DataMonitor'),
        meta: { title: '数据监控', icon: 'dashboard' }
      },
    ]
  }
]

export const endRoutes = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]


//createRouter与reserRouter 一并配合 重置路由信息。直接调用reserRouter函数就可以重置路由信息
const createRouter = () => new Router({
  // mode: 'history', // require service support  //去掉 # 断点
  scrollBehavior: () => ({ x: 0 ,y: 0 }), //页面滚动到顶部的位置
  routes: baseRoutes
})
const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router  所有的 vue-router 注册的路由信息都是存放在matcher
  router.options.routes = baseRoutes
}

export default router
